#!/usr/bin/env python
#coding=utf8

import xlrd
import re

def read_excel_FOF(file_name):
    if not isinstance(file_name, unicode):
        file_name = file_name.decode('utf-8')
    workbook = xlrd.open_workbook(file_name)
    count_sheets = len(workbook.sheets())
    fund_name_list = []
    cash_balance_list = []
    for i in range(count_sheets):
        table = workbook.sheets()[i]
        fund_name = workbook.sheet_names()[i].encode('utf-8')
        fundinfo = ''
        if fund_name.isdigit():
            fundinfo = table.cell(3,0).value
            fundinfo = fundinfo.encode('utf-8')
            startIndex = fundinfo.find('－')
            try:
                fundinfo = fundinfo[startIndex+1:]
            except:
                print 'local variable'
            length = fundinfo.find(' ')
            fund_name = fundinfo[0:length]
            fund_name_list.append(fund_name)
        else:
            fund_name_list.append(fund_name)
        cell_value = table.cell(8,0).value
        cell_value = cell_value.encode('utf-8')
        s = re.compile(r'\d{0,15}\.\d{0,15}')
        cash_balance = float(s.search(cell_value).group())
        cash_balance_list.append(cash_balance)
    return fund_name_list, cash_balance_list

read_excel_FOF('/Users/alala-macbook/Tem/xx.xlsx')